package ThreadSafety;

import java.util.Scanner;

public class Volatile {

    private volatile static int flag = 0;
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while(flag == 0) {

            }
            System.out.println("t1 end");
        });

        Thread t2 = new Thread(() -> {
            System.out.println("flag = ");
            Scanner scanner = new Scanner(System.in);
            flag = scanner.nextInt();
            System.out.println("t2 end");
        });

        t1.start();
        t2.start();
    }
}
